package com.itheima.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.PageResult;
import com.itheima.domain.PmsProduct;
import com.itheima.domain.PmsProductCategory;
import com.itheima.mapper.PmsProductMapper;
import com.itheima.service.PmsProductService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品信息 服务实现类
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@DubboService
public class PmsProductServiceImpl extends ServiceImpl<PmsProductMapper, PmsProduct> implements PmsProductService {

    @Override
    public PageResult pageByParent(Integer brandId, String keyword, Integer pageNum, Integer pageSize, Integer productCategoryId, String productSn, Integer publishStatus, Integer verifyStatus) {
        Page<PmsProduct> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsProduct> lqw = new LambdaQueryWrapper<>();
        //商品品牌编号
        lqw.eq(brandId != null, PmsProduct::getBrandId, brandId);
        //商品名称模糊关键字
        lqw.like(keyword != null, PmsProduct::getName, keyword);
        //商品分类编号
        lqw.eq(productCategoryId != null, PmsProduct::getProductCategoryId, productCategoryId);
        //商号货号
        lqw.eq(productSn != null, PmsProduct::getProductSn, productSn);
        //上架状态
        lqw.eq(publishStatus != null, PmsProduct::getPublishStatus, publishStatus);
        //审核状态
        lqw.eq(verifyStatus != null, PmsProduct::getVerifyStatus, verifyStatus);
        page(page, lqw);
        return new PageResult(pageNum, pageSize, page.getTotal(), page.getPages(), page.getRecords());
    }
}
